<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>

<body>
  <div id="app">
    <h1>{{ count }}</h1>
    <h2>{{ result }}</h2>
    <button @click="count++">+1</button>
  </div>

  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        count: 1,
        num: 2
      },
      watch: {
        // 只要监听的数据count发生改变 就执行
        // 一 对 多
        count(newValue, oldValue) {
          console.log('变化前' + oldValue);
          console.log('count的值发生了改变');
          console.log('变化后' + newValue);
        },
      },
      computed: {
        // 只要依赖的数据[this.count, this.num]发生改变 就执行
        // 多 对 一
        result() {
          return this.count * this.num
        }
      },
      methods: {

      }
    })
    vm.$watch('num', () => {
      console.log('num变了');
    })
  </script>
</body>

</html>